// rentcart.js
var qrcode=require('../../js/qrcode.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    books:[],
    qrcode:null
  },
  openClear:function(){
    wx.removeStorageSync('book1');
    wx.removeStorageSync('book2');
    wx.removeStorageSync('info1');
    wx.removeStorageSync('info2');
    this.setData({
      books:[],
      qrcode:null
    })
    clearInterval(this.interval);
  },
  openRent: function () {
    var userID = wx.getStorageSync('userID');
    wx.request({
      url: 'https://55300249.qcloud.la/JapariFriends/rent',
      data: {
        userId: userID,
        book1: bookid
      },
      method: 'get'
    });
  },

  drawQrCode:function(){
    var that = this;
    var now=new Date();
    var ID1 = wx.getStorageSync('book1');
    var ID2 = wx.getStorageSync('book2');
    var msecond = now.getMilliseconds();
    var userID=wx.getStorageSync('userID');

    var book = userID+','+ID1 + ',' + ID2+','+msecond;
    console.log('draw code');
    that.setData({
      qrcode: qrcode.createQrCodeImg(book, { size: '150' })
    });
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;

    var b1=null;
    var b2 = null;
    b1=wx.getStorageSync('info1');
    b2=wx.getStorageSync('info2');
    that.setData({
      books:[b1,b2]
    });
    console.log(this.data.books);

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.drawQrCode();
    this.interval=setInterval(this.drawQrCode,10000);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  onUnload:function(){
    clearInterval(this.interval);
  },
  onHide:function(){
    clearInterval(this.interval);
  }

})